<?php
function getIP()
{
    static $userip;
    if (isset($_SERVER)){
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $userip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
            $userip = $_SERVER["HTTP_CLIENT_IP"];
        } else {
            $userip = $_SERVER["REMOTE_ADDR"];
        }
    } else {
        if (getenv("HTTP_X_FORWARDED_FOR")){
            $userip = getenv("HTTP_X_FORWARDED_FOR");
        } else if (getenv("HTTP_CLIENT_IP")) {
            $userip = getenv("HTTP_CLIENT_IP");
        } else {
            $userip = getenv("REMOTE_ADDR");
        }
    }
    return $userip;
}

function genQuestions()
{
   include("dbconfig.php");
   header("Content-Type: text/html; charset=gbk");
   $link = mysql_connect($dbhost,$dbuser,$dbpassword) or die('Unable to establish a DB connection');

   mysql_select_db($database,$link);
   mysql_query("SET names GBK");
   $sql="select * from questions";
   $result =mysql_query ($sql);
   if (!$result) echo "SQL错误0：".mysql_error();
   echo "<select id=questions name=questions>";
   while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
              //echo $row[question];
           echo "<option value='$row[id]'>".$row[question]."</option>";
    }
    echo "</select>";
      


}
//genQuestions();

?>
